package src.DAO;

import src.jdbc.PostgreSQL;
import src.Entities.Programa;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

/**
 *
 * @author Rodrigo
 */
public class ProgramaDAO
{

    public ArrayList selectPrograma(String sql)
    {
        ArrayList results = new ArrayList();
        try
        {
            Connection con = PostgreSQL.getConnection();
            Statement select = con.createStatement();
            ResultSet query = select.executeQuery(sql);
            while (query.next())
            {
                Programa program = new Programa(query.getInt("programa_id"),
                        query.getString("nombre"));
                results.add(program);
            }
        }
        catch (Exception e)
        {
            System.out.println(e);
        }
        return results;
    }

     public ArrayList<Programa> listarPrograma() throws SQLException
    {
        Connection con = PostgreSQL.getConnection();
        Statement select = con.createStatement();
        String sql = "select * from programa";
        ResultSet query = select.executeQuery(sql);
        ArrayList<Programa> listaPrograma = new ArrayList();

        while (query.next())
        {
            Programa programa = new Programa ();
            programa.setProgramaId(query.getInt("programa_id"));
            programa.setNombre(query.getString("nombre"));
            listaPrograma.add(programa);
        }
        return listaPrograma;
    }
}
